package com.dly.blog.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dly.blog.controller.BaseController;
import lombok.AllArgsConstructor;
import com.dly.blog.domain.vo.category.CategoryVO;
import com.dly.blog.domain.ro.category.CategoryPageRO;
import com.dly.blog.domain.ro.category.CategoryAddRO;
import com.dly.blog.domain.ro.category.CategoryEditRO;
import com.dly.blog.service.CategoryService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.dly.blog.domain.vo.PageVO;
import com.dly.blog.msg.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
/**
 * <p>
 * 类别 前端控制器
 * </p>
 *
 * @author DLY
 * @since 2024-01-24 13:55:18
 */
@Tag(name = "类别相关")
@AllArgsConstructor
@RestController
@RequestMapping("/content/category")
public class CategoryController extends BaseController {

    private final CategoryService categoryService;

    @PostMapping(value = "/page")
    @Operation(summary = "分页获取类别信息")
    public ResponseEntity<R<PageVO<CategoryVO>>> getCategoryPage(@RequestBody CategoryPageRO categoryPageRO){
        return operate(()-> this.successDate(categoryService.getCategoryPage(categoryPageRO)));
    }

    @PostMapping(value = "/add")
    @Operation(summary = "添加类别信息")
    public ResponseEntity<R<Void>> addCategory(@RequestBody CategoryAddRO categoryAddRO){
        categoryService.addCategory(categoryAddRO);
        return operate(this::success);
    }

    @PostMapping(value = "/edit")
    @Operation(summary = "修改类别信息")
    public ResponseEntity<R<Void>> editCategory(@RequestBody CategoryEditRO categoryEditRO){
        categoryService.editCategory(categoryEditRO);
        return operate(this::success);
    }

    @PostMapping(value = "/get/{id}")
    @Operation(summary = "获取类别信息")
    public ResponseEntity<R<CategoryVO>> getCategory(@PathVariable(value = "id") String id){
        return operate(()-> this.successDate(categoryService.getCategory(id)));
    }

    @PostMapping(value = "/remove/{ids}")
    @Operation(summary = "删除类别信息")
    public ResponseEntity<R<Void>> removeCategory(@PathVariable(value = "ids") String[] ids){
        categoryService.removeCategory(ids);
        return operate(this::success);
    }

}
